package com.netdisk.controller;

import com.netdisk.dto.request.file.DeleteDTO;
import com.netdisk.dto.request.file.RestoreDTO;
import com.netdisk.dto.response.file.FileDTO;
import com.netdisk.dto.response.file.FileListDTO;
import com.netdisk.mapper.TrashMapper;
import com.netdisk.service.TrashService;
import com.netdisk.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "回收站管理")
@RequestMapping("/trash")
@RestController
public class TrashController {

    @Autowired
    private TrashService trashService;
    @ApiOperation(value = "获取回收站列表")
    @GetMapping("/list")
    public Result<FileListDTO> getTrashList(@RequestParam Integer userId) {
        FileListDTO fileListDTO =  new FileListDTO();
        Integer trashCount = trashService.getTrashCountById(userId);
        List<FileDTO> trashList = trashService.getTrashListById(userId);
        fileListDTO.setTotal(trashCount);
        fileListDTO.setList(trashList);
        return Result.success(fileListDTO);
    }

    @ApiOperation(value = "恢复文件")
    @PostMapping("/restore")
    public Result<Object> restoreFile(@RequestBody RestoreDTO deleteDTO) {
        trashService.restoreFile(deleteDTO);
        return Result.success();
    }

    @DeleteMapping("/delete")
    @ApiOperation(value = "彻底删除文件")
    public Result<Object> completelyDelete(DeleteDTO deleteDTO) {
        trashService.completelyDelete(deleteDTO);
        return Result.success();
    }

    @ApiOperation(value = "清空回收站")
    @DeleteMapping("/clear")
    public Result<Object> clearTrash(Integer id) {
        trashService.trashClearById(id);
        return Result.success();
    }



}
